package com.dianda.generic.commons.componet;

import com.dianda.generic.commons.utils.CollectionUtils;
import com.dianda.generic.dao.BaseDao;
import com.dianda.generic.dao.bean.IParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by The_Answer on 2016/7/22.
 */
@Component
public class BaseDaoComponent implements BaseDao {

    @Autowired
    private BaseDao baseDao;

    @Override
    public List<Map<String, Object>> selectDataByParams(IParams params) throws SQLException {
        List<Map<String, Object>> data = baseDao.selectDataByParams(params);
        return CollectionUtils.converMapKeyToLowerCase(data);
    }

    @Override
    public int updateDataByParams(IParams params) throws SQLException {
        return baseDao.updateDataByParams(params);
    }

    public void batchUpateDataByParams(IParams... paramses) throws SQLException {
        for (IParams ip : paramses) {
            updateDataByParams(ip);
        }
    }

    @Override
    public void insertDataByParams(IParams params) throws SQLException {
        baseDao.insertDataByParams(params);
    }

    @Override
    public void deleteDataByParams(IParams params) throws SQLException {
        baseDao.deleteDataByParams(params);
    }

    @Override
    public void createTableByParams(IParams params) throws SQLException {
        baseDao.createTableByParams(params);
    }

    @Override
    public void dropTableByParams(IParams params) throws SQLException {
        baseDao.dropTableByParams(params);
    }

    @Override
    public void alterTableByParams(IParams params) throws SQLException {
        baseDao.alterTableByParams(params);
    }
}
